
// import lazyLoading from './lazyLoading'
// const _import = require('@/router/_import_' + process.env.NODE_ENV)
/* 引入页面 */
import Layout from '../views/layout/Layout'
import Property from '../views/property'
export default (accessedRouter, data) => {
  // 这里之所以要重新遍历一下，是因为，通常我们动态路由的时候，是获取服务端数据，这个component属性是一个字符串，或者可能连字段名都是其他的key
  // 所以这里要做一些转换
  const menuRoot = {
    path: '/property',
    component: Layout,
    name: '项目组',
    leaf: true,
    tag: false,
    meta: { title: '项目组', icon: 'example' }
  }
  menuRoot.children = []
  generaMenu(menuRoot.children, data)
  accessedRouter.push(menuRoot)
  accessedRouter.push({ path: '*', redirect: '/404', hidden: true })
}
function generaMenu(routers, data, prePath) {
  const keys = Object.keys(data)
  if (!prePath || prePath === '') {
    prePath = '/property'
  }
  keys.forEach((item) => {
    const next = typeof data[item] === 'object'
    let path
    let component
    let leaf = true
    if (!next) {
      item = data[item]
      path = item
      // component = { template: '<div>测试:' + prePath + '/' + item + '</div>' }
      component = Property
    } else {
      path = prePath + '/' + item
      component = { template: '<router-view></router-view>' }
      if (data[item].length === 0) {
        leaf = false
      }
    }
    const menu = {
      path: path,
      component: component,
      leaf: leaf,
      tag: false,
      // redirect: item,
      name: path,
      meta: { title: item, icon: 'documentedit' }
    }
    // menu.component = lazyLoading(menu.component)
    if (next && data[item] && data[item].length > 0) {
      menu.children = []
      generaMenu(menu.children, data[item], path)
    }
    routers.push(menu)
  })
}
/* function generaRouter(routers, data, prePath) {
  const keys = Object.keys(data)
  keys.forEach((item) => {
    const next = typeof data[item] === 'object'
    let path
    if (!next) { item = data[item] }
    if (prePath && prePath !== '') {
      path = prePath + '/' + item
    } else {
      path = item
    }

    const router = {
      path: path,
      component: { template: '<div>测试[' + path + ']</div>' },
      name: item,
      meta: { title: item, icon: 'example' }
    }
    if (next && data[item] && data[item].length > 0) {
      generaRouter(routers, data[item], path)
    } else {
      routers.push(router)
    }
  })
}
*/
